package core.rb;

import core.rb.r.MR;
import core.sb.s.Seq;
import gui.processor.Processor;
import gui.utils.ProgBar;
import java.util.ArrayList;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class MB {
    private ArrayList <MR> mrl;
    private Seq ref;
    private int [] qDist ;
    private int maxQ;

    public MB(Seq ref) {
        this.mrl = new ArrayList();
        this.ref = ref;
        this.maxQ = 0;
    }

    public MB(Seq ref, ArrayList <MR> mrl) {
        this.mrl = mrl;
        this.ref = ref;
        this.maxQ = 0;
    }

    public int [] getQDist(){return qDist;}
    public void add(MR mr){mrl.add(mr);}
    public MR getRead(int n){return mrl.get(n);}
    public Seq getRef(){return ref;}
    public int getSize(){return mrl.size();}

    public void genQDist(Processor gp){
        qDist = new int[150];
        gp.dPrg(ProgBar.START, this.getSize());
        String quals;
        for(int r=0; r<this.getSize(); r++){
            quals = this.getRead(r).getQuals();
            for(int q=0; q<quals.length(); q++){
                int val = ((int)quals.charAt(q));
                qDist[val]++;
                if(val>maxQ){maxQ = val;}
            }
            gp.dPrg(ProgBar.UPDATE, r);
        }
        if(gp!=null){gp.dPrg(ProgBar.END, 0);}
    }

    public int getMaxQ(){return maxQ;}
}